#ifndef __DEVICEINFO_H__
#define __DEVICEINFO_H__

#include "BasicInclude.h"

#define BOOTLOADER_ADDR 0x08000000

#define APPLCATION_ADDR	0x08020000			
#define APPINFO_ADDR		0x08021000

#define UPDATEDATA_ADDR 0x08080000

#define	APPDATA_SCT_CNT				0x03			//application data have 3 sectors[sector 5 - 7]
#define UPDATEDATA_SCT_CNT		0x03			//update data have 3 sectors[sector 8 - 10]

#define SYSTEMINFO_ADDR	0x08001000			//存在bin文件中的信息，不可更改，存放版本信息等
#define DEVICEINFO_ADDR	0x08010000			//存在flash中，供bootloader和app共同使用，用于两者之间进行数据信息传递

#define MODEL_NAME	"XPanda BMS"


typedef struct _DeviceInfo
{
	uint8_t model_sn[32];
	char model_name[64];
	uint8_t login_password[8];

	uint8_t update_datetime[64];
	
	bool update_flag;
	bool first_startup;
	
	uint8_t try_startup_times;
	
	uint32_t firmware_size;
	uint16_t firmware_crc;
	
	uint8_t reserved[3];

} DeviceInfo;

typedef struct _SystemInfo
{
	uint16_t u16ModelID;	//0-7
	bool bDeviceConnectServerOK;
	bool bDeviceLoginOK;
	bool bDeviceCanWork;	//服务端是否允许设备工作
	
	
	bool bDevNeedUpdate;	//设备是否需要升级
	uint32_t u32ComSvrID;	//与服务段通信用的标识符ID
	uint32_t u16PackCapcity;	//电池包容量
	uint8_t u8PackSerialCount;	//电池包电池串数
	uint8_t u8DevMCUID[16];			//设备MCUID
	
	
} SystemRunTimeInfo;

DeviceInfo *GetDeviceInfo(void);
SystemRunTimeInfo *GetSysRunTimeInfo(void);

bool isDeviceConnectServerOK(void);
bool canDeviceLoginOK(void);

void setDeviceConnectServerOK(bool bDeviceConnectServerOK);
void setDeviceLoginOK(bool bDeviceLoginOK);

void setDeviceWork(bool canWork);
bool canDeviceWork(void);

uint8_t GetMCUID(uint8_t* idReadBuf);

uint32_t getComServID(void);
void setComServID(uint32_t svrID);

//电池包容量
uint16_t getPackCapcity(void);
void setPackCapcity(uint16_t cap);


//电池包电池串数
uint8_t getPackSerialCount(void);
void setPackSerialCount(uint8_t serCnt);

//设备MCUID
void getDevMCUID(uint8_t* mcuID);
void setDevMCUID(uint8_t* mcuID);

bool getDevNeedUpdate(void);
void setDevNeedUpdate(bool needUpdate);

void Get_Can_Addr(uint16_t *addr);
#endif
